package com.kangye.learnstudent.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.kangye.learnstudent.entity.StudentPaper;
import com.kangye.learnstudent.entity.Subject;
import com.kangye.learnstudent.entity.User;
import com.kangye.learnstudent.service.SubjectService;
import com.kangye.learnstudent.util.RedisStorageUtil;

import com.kangye.learnstudent.entity.Subject;
import com.kangye.learnstudent.service.SubjectService;

import com.kangye.learnstudent.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @program: learndeduo
 * @description: 学科请求接口
 * @author: 高天乐
 * @create: 2021-05-17 14:05
 **/
@RestController
@CrossOrigin
@RequestMapping("/subject")

public class SubjectController {
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private RedisStorageUtil redisStorageUtil;

    //查询所有的课程名
    @RequestMapping("/getsubject")
    public ViewJsonObject getsubject() {
        User user = (User) redisStorageUtil.getKeyOne("studentUserRedisData");
        List<Subject> list = subjectService.getSubject(user);
        if (list != null && list.size() > 0) {
            return new ViewJsonObject(list);
        }
        return null;
    }
        //根据年级查寻各个学科
        public ViewJsonObject<Subject> selSubject (Integer subjectGradeId){
            //返回数据
            return subjectService.selSubject(subjectGradeId);

        }

    }
